<template>
	<view class="container">

		<view class="user-section">
			<view class="user-info-box">
				<view class="portrait-box">
					<image class="portrait" :src="userInfo.photoUrl || '/static/missing-face.png'"></image>
				</view>
				<view class="user-info-contain">
					<view class="user-name-contain" @click="navTo('/package_isp/pages/face/faceCollection')">人脸认证</view>
				</view>
			</view>
		</view>
		<view class="info-box">
			<view class="title-box">
				<view class="title-icon">
					基本信息
				</view>
				<view style="height: 50upx;line-height: 50upx;margin-top:30upx">
					<text class="yticon icon-huifu" style="margin-right: 30upx;font-size: 30upx;color: #00BFFF;" @click="navTo('/package_isp/pages/family/editMyInfo')"
					 v-show="canEdit == 'true'">编辑</text>
				</view>
			</view>
			<view class="list-cell">
				<view class="list-cell-item">
					<view class="item-title">姓名</view>
					<view class="item-info">{{myInfo.name || "未填写"}}</view>
				</view>
				<view class="list-cell-item">
					<view class="item-title">性别</view>
					<view class="item-info">{{myInfo.sex == "1"? "男" :"女"}}</view>
				</view>
				<view class="list-cell-item">
					<view class="item-title">民族</view>
					<view class="item-info">{{myInfo.nation || "未填写"}}</view>
				</view>
				<view class="list-cell-item">
					<view class="item-title">生日</view>
					<view class="item-info">{{myInfo.birthday || "未填写"}}</view>
				</view>
				<view class="list-cell-item">
					<view class="item-title">手机号</view>
					<view class="item-info">{{myInfo.telNo || "未填写"}}</view>
				</view>
				<view class="list-cell-item">
					<view class="item-title">身份证号</view>
					<view class="item-info">{{myInfo.idCard || "未填写"}}</view>
				</view>
				<view class="list-cell-item">
					<view class="item-title">住址</view>
					<view class="item-info">{{myInfo.homeAddress || "未填写"}}</view>
				</view>
				<view class="list-cell-item">
					<view class="item-title">文化程度</view>
					<view class="item-info">{{myInfo.education || "未填写"}}</view>
				</view>
				<view class="list-cell-last">
					<view class="item-title">婚姻状况</view>
					<view class="item-info">{{myInfo.maritalStatus || "未填写"}}</view>
				</view>
			</view>
		</view>

		<view class="info-box">
			<view class="title-box">
				<view class="title-icon">
					成员信息
				</view>
				<view style="height: 50upx;line-height: 50upx;margin-top:30upx">
					<text class="yticon icon-huifu" style="margin-right: 30upx;font-size: 30upx;color: #00BFFF;" @click="goTo('/package_isp/pages/family/editRelation')" v-show="canEdit == 'true'">编辑</text>
				</view>
			</view>
			<view class="list-cell">
				<view :class="index == relationInfo.length - 1?'list-cell-last':'list-cell-item'" v-for="(item,index) in relationInfo"
				 :key="index">
					<view class="item-title">{{item.fromName}}</view>
					<view style="color:#00BFFF;font-size: 24upx;">-- {{item.relationName}} --</view>
					<view class="item-info" @click="goTo('/package_isp/pages/family/myInfo?canEdit=false&ownerId='+item.toId)">{{item.toName}}</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				ownerId: "",
				myInfo: {},
				relationInfo: [],
				canEdit: true
			}
		},
		onShow(option) {
			this.getData()
		},
		onLoad(option) {
			if (option && option.ownerId) {
				this.ownerId = option.ownerId
			}
			if (option && option.canEdit) {
				console.log(option.canEdit)
				this.canEdit = option.canEdit
			}
		},
		methods: {
			getData() {
				let params = {
					id: this.ownerId
				}
				this.$api.request.getOwnerRelationByFromId(params, (res) => {
					if (res.body.status.statusCode == "0") {
						this.myInfo = res.body.data.ownerInfo
						this.relationInfo = res.body.data.relations
					} else if (res.body.status.statusCode == "2") {
						this.$api.msg("该用户未绑定乡村")
					}
				})
			},
			navTo(url) {
				if(this.canEdit == 'true'){
					uni.navigateTo({
						url: url + "?item=" + JSON.stringify(this.myInfo)
					})
				}
			},
			goTo(url) {
				if(this.canEdit == 'true'){
					uni.navigateTo({
						url: url
					})
				}
			}
		}
	}
</script>
<style lang='scss'>
	page {
		background: $page-color-base;
	}

	.user-section {
		width: 100%;
		height: 240upx;
		position: relative;
		background: linear-gradient(to right, rgba(0, 171, 239, 1), rgba(0, 171, 239, 0.6));
		overflow: hidden;

		.bg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
		}
	}

	.info-box {
		width: calc(100% - 40upx);
		margin: 20upx;
		background-color: white;
		border-radius: 20upx;
		overflow: hidden;
	}

	.title-box {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.user-info-box {
		margin-top: 40upx;
		padding-left: 40upx;
		height: 180upx;
		display: flex;
		align-items: center;
		position: relative;
		z-index: 1;

		.portrait {
			width: 130upx;
			height: 130upx;
			border: 5upx solid #fff;
			border-radius: 50%;
		}

		.username {
			font-size: $font-sm;
			color: $font-color-base;
			margin-left: 20upx;
		}
	}

	.user-info-contain {
		margin-left: 40upx;
		width: 70%;
		color: white;
	}

	.user-name-contain {
		font-size: 36rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		font-weight: bold;
	}

	.list-cell {
		padding: 30upx;

		.list-cell-item {
			height: 90upx;
			line-height: 90upx;
			border-bottom: 1px solid #e9eef5;
			display: flex;
			flex-direction: row;
			font-size: 30upx;
			justify-content: space-between;

			.item-title {
				font-weight: border;
				text-align: left;
				margin-left: 20upx;
			}

			.item-info {
				text-align: right;
				margin-right: 20upx;
			}
		}

		.list-cell-last {
			height: 90upx;
			line-height: 90upx;
			display: flex;
			flex-direction: row;
			font-size: 30upx;
			justify-content: space-between;

			.item-title {
				font-weight: border;
				text-align: left;
				margin-left: 20upx;
			}

			.item-info {
				text-align: right;
				margin-right: 20upx;
			}
		}
	}

	.title-icon {
		background-color: #00BFFF;
		color: white;
		font-weight: bold;
		font-size: 30upx;
		padding-left: 20upx;
		width: 160upx;
		border-top-right-radius: 30upx;
		height: 50upx;
		border-bottom-right-radius: 30upx;
		line-height: 50upx;
		margin-top: 30upx;
	}
</style>
